package b.b.c;

import android.content.Context;
import android.content.res.Configuration;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window.Callback;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import b.b.g.h;
import b.b.g.i.g;
import b.b.h.h0;
import b.b.h.n;
import java.util.ArrayList;
import java.util.WeakHashMap;

/* compiled from: ToolbarActionBar */
public class o extends ActionBar {
    public n a;
    public boolean b;
    public Callback c;
    public boolean d;
    public boolean e;
    public ArrayList<androidx.appcompat.app.ActionBar.a> f = new ArrayList();
    public final Runnable g = new a();
    public final androidx.appcompat.widget.Toolbar.e h;

    /* compiled from: ToolbarActionBar */
    public class a implements Runnable {
        public void run() {
            o oVar = o.this;
            Menu r = oVar.r();
            g gVar = r instanceof g ? (g) r : null;
            if (gVar != null) {
                gVar.z();
            }
            try {
                r.clear();
                if (!(oVar.c.onCreatePanelMenu(0, r) && oVar.c.onPreparePanel(0, null, r))) {
                    r.clear();
                }
                if (gVar != null) {
                    gVar.y();
                }
            } catch (Throwable th) {
                if (gVar != null) {
                    gVar.y();
                }
            }
        }
    }

    /* compiled from: ToolbarActionBar */
    public class b implements androidx.appcompat.widget.Toolbar.e {
    }

    /* compiled from: ToolbarActionBar */
    public final class c implements b.b.g.i.m.a {
        public boolean a;

        public void a(g gVar, boolean z) {
            if (!this.a) {
                this.a = true;
                o.this.a.h();
                Callback callback = o.this.c;
                if (callback != null) {
                    callback.onPanelClosed(108, gVar);
                }
                this.a = false;
            }
        }

        public boolean b(g gVar) {
            Callback callback = o.this.c;
            if (callback == null) {
                return false;
            }
            callback.onMenuOpened(108, gVar);
            return true;
        }
    }

    /* compiled from: ToolbarActionBar */
    public final class d implements b.b.g.i.g.a {
        public boolean a(g gVar, MenuItem menuItem) {
            return false;
        }

        public void b(g gVar) {
            o oVar = o.this;
            if (oVar.c == null) {
                return;
            }
            if (oVar.a.b()) {
                o.this.c.onPanelClosed(108, gVar);
            } else if (o.this.c.onPreparePanel(0, null, gVar)) {
                o.this.c.onMenuOpened(108, gVar);
            }
        }
    }

    /* compiled from: ToolbarActionBar */
    public class e extends h {
        public e(Callback callback) {
            super(callback);
        }

        public View onCreatePanelView(int i) {
            if (i == 0) {
                return new View(o.this.a.getContext());
            }
            return this.a.onCreatePanelView(i);
        }

        public boolean onPreparePanel(int i, View view, Menu menu) {
            boolean onPreparePanel = this.a.onPreparePanel(i, view, menu);
            if (onPreparePanel) {
                o oVar = o.this;
                if (!oVar.b) {
                    oVar.a.c();
                    o.this.b = true;
                }
            }
            return onPreparePanel;
        }
    }

    public o(Toolbar toolbar, CharSequence charSequence, Callback callback) {
        b bVar = new b();
        this.h = bVar;
        this.a = new h0(toolbar, false);
        e eVar = new e(callback);
        this.c = eVar;
        this.a.setWindowCallback(eVar);
        toolbar.setOnMenuItemClickListener(bVar);
        this.a.setWindowTitle(charSequence);
    }

    public boolean a() {
        return this.a.e();
    }

    public boolean b() {
        if (!this.a.m()) {
            return false;
        }
        this.a.collapseActionView();
        return true;
    }

    public void c(boolean z) {
        if (z != this.e) {
            this.e = z;
            int size = this.f.size();
            for (int i = 0; i < size; i++) {
                ((androidx.appcompat.app.ActionBar.a) this.f.get(i)).a(z);
            }
        }
    }

    public int d() {
        return this.a.o();
    }

    public Context e() {
        return this.a.getContext();
    }

    public void f() {
        this.a.setVisibility(8);
    }

    public boolean g() {
        this.a.k().removeCallbacks(this.g);
        ViewGroup k = this.a.k();
        Runnable runnable = this.g;
        WeakHashMap weakHashMap = b.i.k.o.a;
        k.postOnAnimation(runnable);
        return true;
    }

    public void h(Configuration configuration) {
    }

    public void i() {
        this.a.k().removeCallbacks(this.g);
    }

    public boolean j(int i, KeyEvent keyEvent) {
        Menu r = r();
        if (r == null) {
            return false;
        }
        boolean z = true;
        if (KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() == 1) {
            z = false;
        }
        r.setQwertyMode(z);
        return r.performShortcut(i, keyEvent, 0);
    }

    public boolean k(KeyEvent keyEvent) {
        if (keyEvent.getAction() == 1) {
            this.a.f();
        }
        return true;
    }

    public boolean l() {
        return this.a.f();
    }

    public void m(boolean z) {
    }

    public void n(boolean z) {
        this.a.n(((z ? 4 : 0) & 4) | (-5 & this.a.o()));
    }

    public void o(boolean z) {
    }

    public void p(CharSequence charSequence) {
        this.a.setWindowTitle(charSequence);
    }

    public final Menu r() {
        if (!this.d) {
            this.a.i(new c(), new d());
            this.d = true;
        }
        return this.a.p();
    }
}
